import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { AddressInfoEntity } from '../../entity/info';
import { AddressInfoService } from '../../service/info';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * 地址信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: AddressInfoEntity,
  service: AddressInfoService,
  pageQueryOp: {
    select: ['a.*', 'b.nickName'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      },
    ],
    where: async ctx => {
      return [['a.userId = :userId', { userId: ctx.user.id }]];
    },
  },
  insertParam: ctx => {
    return {
      userId: ctx.user.id,
    };
  },
})
export class AppAddressInfoController extends BaseController {
  @Inject()
  addressInfoService: AddressInfoService;

  @Inject()
  ctx;
}
